<!DOCTYPE html>
<html class="loginHtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登陆 · 管理后台</title>
    <link rel="stylesheet" href="/static/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body class="loginHtml">
    <div class="loginBody">
        <form class="layui-form" action="" method="post">
            <div class="login_face"><img src="/static/images/logo.jpg" class="userAvatar"></div>
            <div class="layui-form-item input-item">
                <label for="userName">用户名</label>
                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" id="userName" class="layui-input" lay-verify="required">
            </div>
            <div class="layui-form-item input-item">
                <label for="password">密码</label>
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input" lay-verify="required">
            </div>
            <div class="layui-form-item input-item" id="imgCode">
                <label for="code">验证码</label>
                <input type="text" name="captcha_code" placeholder="请输入验证码" autocomplete="off" id="code" class="layui-input">
                <a href="javascript:void(0);">
                    <img class="captcha" id="captcha" src="{:url('index/captcha')}" />
                </a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
            </div>
        </form>
    </div>
<script src="/static/layui.js"></script>
<script>
    layui.use(['jquery','layer','form'], function(){
        if(window.top != window.self){
            window.top.location = '{:url("index/login")}';
            return false;
        }
        var $ = layui.$,layer = layui.layer,form = layui.form;
        form.on('submit(login)', function(data){
            var index = layer.load(1);
            $.post('{:url("index/login")}',data.field,function (data) {
                if(data.code == 0){
                    window.location.href = '{:url("index/index")}';
                }else{
                    layer.close(index);
                    layer.msg(data.msg);
                    $("#imgCode img").click();
                }
            });
            return false;
        });
        $("#imgCode img").click(function(){
            $(this).attr('src',"{:url('index/captcha')}?time="+Math.random());
        });
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        });
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        });
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        })
    });
</script>
</body>
</html>